define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    
    require('../../su/accordion/oaListCtrl');
    require('../asset/detail/wrDetailCtrl');
    require('../workreportContentCtrl');
    var rk_userService = require('core/services/2.0/rk_userService');

    //该ctrl继承了oaListCtrl，具体数据加载是在 那里执行
    //在本ctrl中，只处理具体业务事件
    $.widget('rk.wrListCtrl', $.rk.oaListCtrl, {
        _create: function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;

            elem.attr('id', opt.id).addClass('wr-list').data('wrListCtrl', true);
        },
        _init: function () {
            var me = this;
            var elem = me.element;
            var opt = me.options;

            me._super();

            var myBody = elem.find('>.oa-result-body');
            if(me.options.viewtype == 'mine'){
                myBody.addClass('oa-list report-list-area daily-paper-list  my-daily-paper clear');
            }else{
                myBody.addClass('oa-list report-list-area daily-paper-list clear');
            }
            
        },
        bindData: function (list, templateId) {
            var me = this;
            var elem = me.element;
            for (var i = 0, len = list.length; i < len; i++) {
                var report = list[i];
                report = me._asReportInfo(report);
            }
            me._super(list, templateId);

            if(list.length == 0){
                me.beBlank(rk.i18n('WORKREPORT_NOT_EXISTS'));
            }
        },
        _handleRowSelect: function (row, event) {
            //行点击方法，在父类中触发
            var me = this;
            var elem = me.element;
            var opt = me.options;

            var reportId = row.attr('reportid');
            var ownerId = row.attr('ownerId');
            var typeAlias = row.attr('typeAlias');

            elem.find('div.show-content-hover').removeClass('show-content-hover');
            row.addClass('show-content-hover');
            var currentId = $('#taskDetailDiv').wrDetailCtrl('getCurrentId');

            if (!$(event.target).hasClass("delete")) {
                rk.oa.popupContent(function (contentElem) {
                    contentElem.workreportContentCtrl({
                        reportid: reportId,
                        ownerid: ownerId,
                        typeAlias: typeAlias,
                        listId: opt.id
                    });
                });
            } else {
                workreportService.deleteReport(reportId, function () {
                    rk.oa.removeContent();
                    row.parents('.oa-tab').find('.oa-tab-header > a.active').click();
                    rk.noticeSuccess(rk.i18n('APPS_COMMENT_DELETE_FAILURE'));

                });
            }


        },
        _asReportInfo: function (report) {
            var me = this;
            var belongTypeId = report.type;
            var belongTypeInfo = workreportService.getBelongType(belongTypeId);
            report.typeAlias = belongTypeInfo.alias;
            report.textType = belongTypeInfo.typeName;//$('#wr-tab').wrTabCtrl('getSelectedText');
            var startDateMs = moment(parseFloat(report.date));
            report.textDate = me._getDateText(startDateMs, belongTypeInfo);
            report = workreportService.getBooleanStatus(report);
            if (me.options.viewtype != 'mine') report = me._asCollageReportInfo(report);
            return report;
        },
        _asCollageReportInfo: function (report) {
            var me = this;
            var userId = report.createdBy;
            var ownerInfo = rk_userService.getUserInfo(userId);

            if (!report.userType) {
                report.userType = '1';//我下属的报告，userType没过来，默认全是1
            }
            if (ownerInfo) {
                report.ownerInfo = ownerInfo;
            }
            return report;
        },
        _getDateText: function (m, belongTypeInfo) {
            return workreportService.getDateTitle(m, belongTypeInfo.alias);
        },
        setDisplayType: function (type) {
            var me = this;
            var elem = me.element;
        },
        _delClicked: function (aObj) {

        },
        beNoData: function () {
            var me = this;
            var elem = me.element;
            var con = elem.find('.report-list-area:first');
            con.html('<div class="task-list-none">'+rk.i18n('WORKREPORT_NOT_EXISTS')+'</div>');
        },
        removeNoData: function () {
            var me = this;
            var elem = me.element;
            var con = elem.find('.report-list-area:first');
            con.find('.task-list-none').remove();
        },
        setApproved: function (reportId) {
            var me = this;
            var elem = me.element;
            var reportDivs;
            if (reportId == 'all') {
                reportDivs = elem.find('div.show-content[reportId][isCc!="true"]');
            } else {
                reportDivs = elem.find('div.show-content[reportId="' + reportId + '"]');
            }
            reportDivs.find('.report-status.unread').remove();
        },
        setCommentNum: function (reportId, number) {
            var me = this;
            var elem = me.element;
            var reportDiv = elem.find('div.show-content[reportId="' + reportId + '"]');
            if(reportDiv.size()){
                reportDiv.find('.comment-num').html(number);
            }

        },
        cleanData: function () {
            var me = this;
            var elem = me.element;
            var con = elem.find('.report-list-area:first');
            con.html('');
        }
    });
});